<!-- -*- mode: R -*- -->
  <!--
  ## This program is fre esoftware: you can redistribute it and/or modify
  ## it under the terms of the GNU General Public License as published by
  ## the Free Software Foundation, either version 3 of the License, or
  ## any later version.
  ##
  ## This program is distributed in the hope that it will be useful,
  ## but WITHOUT ANY WARRANTY; without even the implied warranty of
  ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  ## GNU General Public License for more details.
  ##
  ## You should have received a copy of the GNU General Public License
  ## along with this program.  If not, see <http://www.gnu.org/licenses/>.
  -->
  
  <%
setContentType("text/html")
#RApacheOutputErrors(TRUE)
options(hverbose=FALSE,verbose=FALSE)
%>
  
<html>
<head>
<title>Strategico: search Item</title>
</head>
<body>

  
  <%
strategico.home <- as.character(Sys.getenv("STRATEGICO_HOME"))
source(file.path(strategico.home, "strategico_util.R"))
project.name <- ifelse(is.null(GET$project), "sample", GET$project)
project.config <- Project.GetConfig(project.name=project.name)
value <- ifelse(is.null(GET$value), "V1", GET$value)
project.keys <- GetKeyNames(project.config$keys)

id <- ifelse(is.null(GET$id), 1, GET$id)

if (is.null(GET$KEY1)) {
  keys.item1 <- Item.GetKeys(project.name=project.name, id=id)
  for (k in project.keys)
    GET[[k]]=keys.item1[k]
} else {
  for (k in project.keys)
    GET[[k]]=ifelse(is.null(GET[[k]]), "", GET[[k]])
}
 
key.names <- grep("KEY", names(GET), value=TRUE)
keys <- as.character( unlist(GET[key.names]))
keys.string <- paste(keys, collapse = " - ")
%>
  <center>
    <h1><img src="http://www.r-project.org/Rlogo.jpg" />Strategico :: <%=project.name%> :: <%=keys.string%></h1>
  </center>
<%
id.result <- Item.GetIDs(project.name=project.name, keys=keys )
if (!is.na(id.result) & !is.null(id.result) & length(id.result)>0) {
  id <- id.result[1] %>
<br /><br />Item no. <%=id%> FOUND!  <form action="item.brew" method="GET">
                <%=BuildHtmlElement_input(name="project", default=project.name, type="hidden")%>
                <%=BuildHtmlElement_input(name="id", default=id, type="hidden")%>
                <%=BuildHtmlElement_input(name="value", default=value, type="hidden")%>
                Show results or (re)run of item <input type="submit" value="<%=keys.string%>">
                </form>
<%}%>
  
<br />
<br />
                <form method="GET">
                <input type="submit" value="Search new item">
                <%=BuildHtmlElement_input(name="project", default=project.name, type="hidden")%>
                <%=BuildFormElement_keys(project.name=project.name, defaults=keys)%>
                <%=BuildFormElement_value(project.name=project.name, default=value)%>
                </form>
<% ShowTemplate('footer') %>

